/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package common.xmlObjects;

import com.sun.org.apache.xerces.internal.parsers.DOMParser;
import java.io.IOException;
import java.io.StringReader;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

/**
 *
 * @author Richard Irons
 */
public class BaseConnectionXML extends XMLRootNode {
    private XMLAttribute action;
    private XMLAttribute object;
    public static final String ACTIONNAME = "action";
    public static final String OBJECTNAME = "object";

    public static final String SERVER = "server";
    public static final String CLIENT = "client";

    /**
     * Object static value, failed, to tell the client that an object has failed
     */
    public static final String FAILED = "failed";
    /**
     * Object static value, category, used to set object to category
     */
    public static final String CATEGORY = "category";
    /**
     * Object static value, component, used to set object to component
     */
    public static final String COMPONENT = "component";
    /**
     * Object static value, product, used to set object to product
     */
    public static final String PRODUCT = "product";
    /**
     * Action value, add, used to set the action to add
     */
    public static final String ADD = "add";
    /**
     * Action value, edit, used to set the action to edit
     */
    public static final String EDIT = "edit";
    /**
     * Action value, delete, used to set the action to delete
     */
    public static final String DELETE = "delete";
    /**
     * Action value, get, used to set the action to get
     */
    public static final String GET = "get";
    /**
     * Action value, getall, used to set the action to get all
     */
    public static final String GETALL = "getall";
    /**
     * Action value, update, used to set the action to update
     */
    public static final String UPDATE = "update";

    protected BaseConnectionXML() {
        this(null,null,null);
    }

    protected BaseConnectionXML(String connectionType,String action, String object) {
        super(connectionType, null);
        this.action = new XMLAttribute(ACTIONNAME, action);
        this.object = new XMLAttribute(OBJECTNAME, object);

        addAtrribute(this.action);
        addAtrribute(this.object);        
    }
    /**
     * This function takes an xml string and converts it to a DOM document.
     * @param XMLStr
     * @return
     */
    public static Document XMLStrTODOMDoc(String XMLStr) {
        DOMParser dom_parser = new DOMParser();
        try {
            dom_parser.parse(new InputSource(new StringReader(XMLStr)));
        }
        catch (Exception e) {
            e.printStackTrace();
        }

        Document document = dom_parser.getDocument();
        return document;
    }
    public String getActionValue() {
        return action.getAttribValue();
    }

    public void setActionValue(String action) {
        this.action.setAttribValue(action);
    }

    public String getObjectValue() {
        return object.getAttribValue();
    }

    public void setObjectValue(String object) {
        this.object.setAttribValue(object);
    }
}